package com.data.JVM.chapter08;

/**
 * 动态分派与重写  ：运行期，实际类型确定方法执行版本的分派
 *
 *  指定编码编译： javac  -encoding utf-8  DynamicDispatcher.java
 *
 *  invokevirtual多态指令的查找

 *
 */
public class DynamicDispatcher {

    static abstract class Human{
        protected abstract void sayHello();
    }

    static class Man extends DynamicDispatcher.Human{


        protected void sayHello() {
            System.out.println("hello man");
        }
    }

    static class Woman extends Human{

        protected void sayHello() {
            System.out.println("woman  coming!");
        }
    }

    public static void main(String[] args) {
        Human man = new Man();
        Human woman = new Woman();
        man.sayHello();
        woman.sayHello();

         man = new Woman();
         man.sayHello();


    }
}
